<%inherit file="base.html"/>

<%def name="head()">
<script>
function do_submit(){
    $("#query_form").attr("action", "/admin/customer");
    $("#query_form").submit();
}

function do_export(){
    $("#query_form").attr("action", "/admin/customer/export");
    $("#query_form").submit();
    setTimeout(function(){$("#query_form").attr("action", "/admin/customer");}, 0);
}

function do_delete(customer_id)
{
    if(confirm("删除用户将删除用户所有相关数据，包括账号，日志，订单等，不可恢复，确认操作吗？")) {
        window.location.href = "/admin/customer/delete?customer_id="+customer_id;
    }
    
}
</script>
</%def>

<%def name="body()">
<section class="content">
    <div class="box box-primary">
        <div class="box-header">
            <i class="fa fa-users"></i>
            <h3 class="box-title">用户列表</h3>
        </div>
        <div class="box-body">
            <div class="container">
        <form id="query_form" class="form-horizontal form-well" role="form" action="/admin/customer" method="post">
        ${xsrf_form_html()}
            <div class="form-group">
                <label for="node_id" class="col-md-1 control-label">区域</label>
                <div class="col-md-3">
                    <select id="node_id" name="node_id" class="form-control" >
                    <option value=""></option>
                        % for node in node_list:
                          <option value="${node.id}" ${str(node.id)==node_id and "selected" or ""}>${node.node_desc}</option>
                        % endfor
                    </select>
                </div>            
                <label for="realname" class="col-md-1 control-label">姓名</label>
                <div class="col-md-3">
                    <input type="text" id="realname" name="realname" class="form-control" placeholder="模糊查询" value="${realname and unicode(realname,'utf-8') or ''}">
                </div>
                <label for="idcard" class="col-md-1 control-label">证件</label>
                <div class="col-md-3">
                    <input type="text" id="idcard" name="idcard" class="form-control" placeholder="身份证件号" value="${idcard or ''}">
                </div>
            </div>
            <div class="form-group">
 
                <label for="mobile" class="col-md-1 control-label">手机</label>
                <div class="col-md-3">
                    <input type="text" id="mobile" name="mobile" class="form-control" placeholder="手机号" value="${mobile or ''}">
                </div>                                            
                <label for="user_name" class="col-md-1 control-label">账号</label>

                <div class="col-md-3">
                    <input type="text" id="user_name" name="user_name" class="form-control" placeholder="模糊查询" value=${user_name or ""}>
                </div>
                <label for="state" class="col-md-1 control-label">状态</label>

                <div class="col-md-3">
                    <select id="status" name="status" class="form-control">
                        <option></option>
                        % for k,v in {1:u"正常", 2:u"停机" , 3:u"销户", 4:u"到期", 6:u"未激活"}.items():
                        <option value="${k}"  ${str(k)==status and "selected" or ""} >${v}</option>
                        % endfor
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label for="product_id" class="col-md-1 control-label">资费</label>
                <div class="col-md-3">
                    <select id="product_id" name="product_id" class="form-control" >
                    <option value=""></option>
                        % for product in products:
                          <option value="${product.id}"  ${str(product.id)==product_id and "selected" or ""}>${product.product_name}</option>
                        % endfor
                    </select>
                </div>  
                <label for="address" class="col-md-1 control-label">地址</label>
                <div class="col-md-3">
                    <input type="text" id="address" name="address" class="form-control" placeholder="模糊查询" value=${address or ""}>
                </div>
                <label for="expire_days" class="col-md-2 control-label">账号到期剩余天数</label>
                <div class="col-md-2">
                    <input type="text" id="expire_days" name="expire_days" class="form-control" value=${expire_days or ""}>
                </div>
            </div>
            <div class="form-group">
                <div class="col-md-offset-5 col-md-7">
                    <button type="button" onclick="do_submit();" class="btn btn-primary">查询</button>
                    % if permit.match(current_user.username,'/admin/customer/export'):
                    <a href="javascript:do_export();" class="btn btn-md btn-default"><span class="glyphicon glyphicon-arrow-down"></span>导出用户信息</a>
                    % endif
                </div>
            </div>
        </form>

        <table class="table table-hover">
            <thead>
            <tr>
                <th>区域</th>
                <th>用户账号</th>
                <th>用户姓名</th>
                <th>状态</th>
                <th>资费</th>
                <th>创建时间</th>
                <th>到期时间</th>
                <th></th>
            </tr>
            </thead>
            <tbody>
            % for customer,account,product_name,node_desc in page_data.result:
            <tr>
                <td>${node_desc}</td>
                <td>
                    <a href="/admin/customer/detail?account_number=${account.account_number}">${account.account_number}</a>
                </td>
                <td>${customer.realname}</td>
                <td>
                    % if utils.is_expire(account.expire_date) or account.status == 4:
                        <span class="label label-warning">到期</span>
                    % elif account.status == 1:
                        <span class="label label-success">正常</span>
                    % elif account.status == 2:
                        <span class="label label-default">停机</span>
                    % elif account.status == 3:
                        <span class="label label-danger">销户</span>
                    % endif
                </td>
                <td>${product_name}</td>
                <td>${customer.create_time}</td>
                <td>${account.expire_date}</td>
                <td>
                    <a class="opt-btn btn-default" href="/admin/customer/detail?account_number=${account.account_number}">用户受理</a>
                </td>
            </tr>
            % endfor
            </tbody>
        </table>
        ${page_data.render(form_id="query_form")}
    </div>
</div>
</div>
</section>

</%def>